#ifndef UC_MOD_TALK_H
#define UC_MOD_TALK_H
/*
 * For:  本模块嵌入apache中，负责接收post消息，然后处理，将消息传递给另外一个或者多个服务器
 * Date: 2008.8.12
 * Author: hongzx  zhixiong.hong@unioncast.net
 */

#include "ap_config.h"
#include "apr.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
#include "util_script.h"
#include "http_connection.h"

// 全局宏定义
#define MAX_DATA_SIZE			(256*1024)	// 256k
#define DEFAULT_TIMEOUT 		2000		// 5 seconds

#define REQUEST_URI				"/search"
#define REQUEST_URI2			"//search"
#define MODULE_METHOD			M_GET
#define CONFIG_OPTION_HOST		"SEARCH_HOST"
#define CONFIG_OPTION_PORT		"SEARCH_PORT"
#define MODULE_NAME				"mod_search"

#define TRY_TIMES				2
#define ERROR_MESSAGE			"error"

//#define MAX_SERVER_LEN			128
//#define CONFIGOPTION_LEN 		(MAX_SERVER_LEN+4)

#define RES_ERROR				"400"
#define RES_OK					"200"


typedef const char *(*__take1) ();

/* register the  module */
static void search_hooks(apr_pool_t *p); 

/* Create config rec for host, alloc memory for config */
static void* search_create_server_conf(apr_pool_t* pool, server_rec *s); 

/* read director or option from http.conficommand_rec */
static const char* search_set_config_option_host(cmd_parms* parms, void *cfg, const char* arg); 
static const char* search_set_config_option_port(cmd_parms* parms, void *cfg, const char* arg); 

/* read configure, init the module */
static int init(request_rec*  r);

/* read post data  */
//static int read_post_data(request_rec* r, char* c_buf, apr_size_t* data_size);

/* handler of module, it is the core function */
static int search_handler(request_rec* r);

/* handle data */
static int handle(request_rec* r, const char* data, unsigned int len);
static int handle_error(request_rec* r, const char* message, const char* result);

#endif
